package com.zhkj.txg.module.order.model

import com.zhkj.lib.http.BaseApiService
import com.zhkj.lib.http.BaseResponse
import com.zhkj.txg.module.order.entity.*
import io.reactivex.Observable
import retrofit2.http.*

interface OrderApi : BaseApiService {
    @FormUrlEncoded
    @POST("api/cart/buyNow")
    fun buyNow(
        @Field("token") token: String, @Field("goods_id") goodsId: Int,
        @Field("goods_num") number: Int, @Field("shop_id") specId: Int
    ): Observable<OrderSubmitDetailResponse>

    @FormUrlEncoded
    @POST("api/group_order/buy")//GroupOrder - 拼团购买
    fun groupBuyNow(
        @Field("token") token: String, @Field("goods_id") goodsId: Int,
        @Field("goods_num") number: Int, @Field("item_id") specId: Int = 0,
        @Field("group_id") group_id: Int = 0, @Field("type") type: Int = 1,//购买类型 0单买 1团购 //拼团ID
        @Field("share_id") shareId: Int = 0
    ): Observable<OrderSubmitGroupResponse>

    @GET("api/user/addressList")
    fun addressList(@Query("token") token: String): Observable<AddressListResponse>

    @GET("api/user/addressDetail")
    fun addressDetail(
        @Query("token") token: String,
        @Query("id") id: Int
    ): Observable<AddressDetailResponse>

    @FormUrlEncoded
    @POST("api/user/saveAddress")
    fun addAddress(
        @Field("token") token: String, @Field("id") id: Int = 0,
        @Field("consignee") consignee: String, @Field("gender") gender: Int,
        @Field("mobile") mobile: String, @Field("province") provinceId: Int,
        @Field("city") cityId: Int, @Field("district") districtId: Int,
        @Field("address") address: String, @Field("is_default") isDefault: Int
    ): Observable<BaseResponse>

    @FormUrlEncoded
    @POST("api/order/submitOrder")
    fun submit(
        @FieldMap map: Map<String, String>
    ): Observable<OrderSubmitResponse>

    @FormUrlEncoded
    @POST("api/group_order/submitOrder")//GroupOrder - 拼团购买:提交订单支付
    fun groupSubmit(
        @Field("token") token: String,
        @Field("type") type: Int = 1,//购买类型 0单买 1团购 //拼团ID
        @Field("goods_id") goodsId: Int? = 0,
        @Field("goods_num") number: Int,
        @Field("item_id") specId: String,
        @Field("group_id") group_id: Int = 0,
        @Field("address_id") addressId: Int,
        @Field("coupon_id") couponId: Int = 0,
        @Field("user_note") user_note: String,
        @Field("share_id") shareId: Int
    ): Observable<OrderSubmitResponse>

//    @FormUrlEncoded
//    @POST("api/order/payOrder")
//    fun payOrder(
//        @Field("token") token: String, @Field("order_id") orderId: Long,
//        @Field("order_sn") orderSignNumber: String, @Field("pay_type") payType: String
//    ): Observable<OrderPayResponse>

    @FormUrlEncoded
    @POST("api/order/payOrder")
    fun payOrder(
        @FieldMap map: Map<String, String>
    ): Observable<OrderPayResponse>

    @FormUrlEncoded
    @POST("api/group_order/payOrder")
    fun groupPayOrder(
        @Field("token") token: String, @Field("order_id") orderId: Long,
        @Field("order_sn") orderSignNumber: String, @Field("pay_type") payType: String
    ): Observable<OrderPayResponse>

    @FormUrlEncoded
    @POST("api/cart/settlement")
    fun cartBuy(
        @Field("cart_ids[]") cartIds: MutableList<String>, @Field("shop_id") shopId: String
    ): Observable<OrderSubmitDetailResponse>


//    @FormUrlEncoded
//    @POST("api/cart/settlement")
//    fun cartBuy(
//        @Field("token") token: String,
//        @Field("cart_ids[0]") cartIds: String,
//        @Field("cart_ids[1]") cartId: String,
//        @Field("address_id") addressId:Int
//    ): Observable<OrderSubmitDetailResponse>

    @GET("api/order/index")
    fun orderList(
        @Query("token") token: String,
        @Query("page") page: Int,
        @Query("rows") rows: Int,
        @Query("type") type: String
    ): Observable<OrderListResponse>

    @GET("api/group_order/index")
    fun groupOrderList(
        @Query("token") token: String,
        @Query("page") page: Int,
        @Query("rows") rows: Int,
        @Query("type") type: String
    ): Observable<OrderListResponse>

    @FormUrlEncoded
    @POST("api/order/cancelOrder")
    fun orderCancel(
        @Field("token") token: String,
        @Field("order_id") orderId: Long
    ): Observable<OrderCancelResponse>

    //拼团： 取消订单 订单未支付
    @FormUrlEncoded
    @POST("api/group_order/cancel")
    fun groupOrderCancel(
        @Field("token") token: String,
        @Field("order_id") orderId: Long
    ): Observable<OrderCancelResponse>

    @GET("api/order/detail")
    fun orderDetail(
        @Query("token") token: String,
        @Query("order_id") orderId: Long
    ): Observable<OrderDetailResponse>

    //拼团：订单详情
    @GET("api/group_order/detail")
    fun groupOrderDetail(
        @Query("token") token: String,
        @Query("order_id") orderId: Long
    ): Observable<OrderDetailResponse>

    @GET("api/order/express")
    fun shippingDetail(
        @Query("token") token: String,
        @Query("order_id") orderId: Long
    ): Observable<OrderShippingResponse>

    //拼团：物流详情
    @GET("api/group_order/express")
    fun groupShippingDetail(
        @Query("token") token: String,
        @Query("order_id") orderId: Long
    ): Observable<OrderShippingResponse>

    @FormUrlEncoded
    @POST("api/order/confirm")
    fun receiveOrder(
        @Field("token") token: String,
        @Field("order_id") orderId: Long
    ): Observable<ReceiveOrderResponse>

    //拼团：确认收货
    @FormUrlEncoded
    @POST("api/group_order/confirm")
    fun groupReceiveOrder(
        @Field("token") token: String,
        @Field("order_id") orderId: Long
    ): Observable<ReceiveOrderResponse>

    @GET("api/order/applyRefund")
    fun refundGoods(
        @Query("token") token: String,
        @Query("order_id") orderId: Long,
        @Query("goods_id") goodsId: Long
    ): Observable<RefundGoodsResponse>

    //拼团：申请退款
    @GET("api/group_order/applyRefund")
    fun groupRefundGoods(
        @Query("token") token: String,
        @Query("order_id") orderId: Long,
        @Query("goods_id") goodsId: Long
    ): Observable<RefundGoodsResponse>

    @FormUrlEncoded
    @POST("api/order/submitRefund")
    fun refundSubmit(
        @Field("token") token: String,
        @Field("order_id") orderId: Long,
        @Field("goods_id") GoodsId: Long,
        @Field("type") type: Int,
        @Field("goods_status") goodsStatus: Int,
        @Field("reason") reason: String,
        @Field("describe") describe: String,
        @Field("images") images: String
    ): Observable<BaseResponse>

    //拼团：提交申请退款/退货/换货
    @FormUrlEncoded
    @POST("api/group_order/submitRefund")
    fun groupRefundSubmit(
        @Field("token") token: String,
        @Field("order_id") orderId: Long,
        @Field("goods_id") GoodsId: Long,
        @Field("type") type: Int,
        @Field("goods_status") goodsStatus: Int,
        @Field("reason") reason: String,
        @Field("describe") describe: String,
        @Field("images") images: String
    ): Observable<BaseResponse>

    @GET("api/order/refundDetail")
    fun refundDetail(
        @Query("token") token: String,
        @Query("refund_id") refundId: Long,
        @Query("order_id") orderId: Long,
        @Query("goods_id") goodsId: Long
    ): Observable<RefundDetailResponse>

    //拼团：退款/退货详情
    @GET("api/group_order/refundDetail")
    fun groupRefundDetail(
        @Query("token") token: String,
        @Query("order_id") orderId: Long,
        @Query("goods_id") goodsId: Long
    ): Observable<RefundDetailResponse>

    @FormUrlEncoded
    @POST("api/order/cancelRefund")
    fun refundUndo(
        @Field("token") token: String,
        @Field("order_id") orderId: Long,
        @Field("goods_id") GoodsId: Long
    ): Observable<BaseResponse>

    //拼团：撤销申请退款/退货
    @FormUrlEncoded
    @POST("api/group_order/cancelRefund")
    fun groupRefundUndo(
        @Field("token") token: String,
        @Field("order_id") orderId: Long,
        @Field("goods_id") GoodsId: Long
    ): Observable<BaseResponse>

    @GET("api/common/getDelivery")
    fun getDeliveryList(): Observable<DeliveryResponse>

    @FormUrlEncoded
    @POST("api/order/submitDelivery")
    fun submitDelivery(
        @Field("token") token: String,
        @Field("order_id") orderId: Long,
        @Field("goods_id") goodsId: Long,
        @Field("code") code: String,
        @Field("shipping_no") shippingNo: String
    ): Observable<BaseResponse>

    //拼团：提交物流信息
    @FormUrlEncoded
    @POST("api/group_order/submitDelivery")
    fun groupSubmitDelivery(
        @Field("token") token: String,
        @Field("order_id") orderId: Long,
        @Field("goods_id") goodsId: Long,
        @Field("code") code: String,
        @Field("invoice_no") shippingNo: String
    ): Observable<BaseResponse>

    @FormUrlEncoded
    @POST("api/order/submitComment")
    fun submitEvaluate(
        @Field("token") token: String,
        @Field("order_id") orderId: Long,
        @Field("comment") comment: String
    ): Observable<BaseResponse>

    //拼团：提交商品评价
    @FormUrlEncoded
    @POST("api/group_order/submitComment")
    fun groupSubmitEvaluate(
        @Field("token") token: String,
        @Field("order_id") orderId: Long,
        @Field("goods_id") goods_id: Long,
        @Field("goods_rank") goods_rank: Int,
        @Field("comment") comment: String,
        @Field("images") images: String
    ): Observable<BaseResponse>

    @FormUrlEncoded
    @POST("api/user/delAddress")
    fun deleteAddress(
        @Field("token") token: String,
        @Field("id") id: Long
    ): Observable<BaseResponse>

    @FormUrlEncoded
    @POST("api/order/delete")
    fun deleteOrder(@Field("token") token: String, @Field("order_id") orderId: Long): Observable<ReceiveOrderResponse>

    @FormUrlEncoded
    @POST("api/group_order/delete")
    fun deleteGroupOrder(
        @Field("token") token: String,
        @Field("order_id") orderId: Long
    ): Observable<ReceiveOrderResponse>
}